"""
@Project ：Python_Learning 
@File    ：队列.py
@IDE     ：PyCharm 
@Author  ：zhupp
@Date    ：2024/10/17 16:55 
"""
class Queue:
    #队列初始化
    def __init__(self):
        self.items = []

    #判断队列是否为空
    def is_empty(self):
        return self.items == []

    #元素入队
    def enter_queue(self, item):
        self.items.insert(0, item)

    #队首元素出队
    def go_queue(self):
        return self.items.pop()

    #返回队列长度
    def size(self):
        return len(self.items)

    #清空队列
    def clear(self):
        self.items.clear()

    #获取队首元素
    def getTop(self):
        return self.items[self.size()-1]

    #遍历队列
    def display(self):
        return self.items

class QueueCircle:
    def __init__(self, maxsize=10):
        self.queue = [0 for _ in range(maxsize)]
        self.maxsize = maxsize
        self.rear = 0     # 队首指针
        self.front = 0    # 队尾指针

    def is_empty(self):
        return self.rear == self.front

    def is_full(self):
        return (self.rear + 1) % self.maxsize == self.front

    def push(self, val):
        if not self.is_full():
            self.rear = (self.rear + 1) % self.maxsize
            self.queue[self.rear] = val
        else:
            raise IndexError("Queue is full")

    def pop(self):
        if not self.is_empty():
            self.front = (self.front + 1) % self.maxsize
            return self.queue[self.front]

    def print_queue(self):
        list_queue_r_f = []
        for i in range(self.rear, self.front, -1):
            list_queue_r_f.append(self.queue[i])
        print(list_queue_r_f)


q = QueueCircle()
q.print_queue()
q.push(1)
q.push(2)
q.push(3)
q.push(4)
q.pop()
q.print_queue()
